const fs = require('fs-extra')
const execa = require('execa')
const args = require('minimist')(process.argv.slice(2))
const {
  targets
} = require('./util')

const test = args.TEST

;
(async () => {
  for (const target of targets) {
    await fs.remove(`packages/${target}/dist`)
    await runExeca(target)
  }
})()

async function runExeca(target) {
  await execa(
    'rollup',
    [
      '-c',
      '--environment',
      [`TARGET:${target}`, `__TEST__:${test ? test : 'test'}`]
    ], {
      stdio: 'inherit'
    }
  )
}